package mediatheque.view;

import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.LayoutStyle;
import javax.swing.WindowConstants;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionListener;

import mediatheque.model.GestionnaireModel;
import mediatheque.model.MediathequeModel;

public class GestionnaireView extends JDialog {
	
	protected MediathequeModel model;
	
    protected JButton btnAnnuler;
    protected JButton btnEnregistrer;

    protected JScrollPane jScrollPane1;
        
    protected JLabel lblTitre;
    protected JLabel lblNom;
    protected JLabel lblPrenom;
    protected JLabel lblEmail;
    protected JLabel lblAdresse;
    protected JLabel lblLogin;
    protected JLabel lblPassword;
    

    protected JTextField tfNom;  
    protected JTextField tfPrenom; 
    protected JTextField tfEmail; 
    protected JTextPane tpAdresse;
    protected JTextField tfLogin;
    protected JPasswordField pfPass;
	
	
	public GestionnaireView(MediathequeModel model, JFrame parent) {
		super(parent, "Gestion d'un gestionnaire", true);
		this.model = model;	

		setSize(410, 400);
		setLocationRelativeTo(null);
		setResizable(false);
        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
		
		initialiserComposants();		
	}

	protected void initialiserComposants() {
				
		Font font = new java.awt.Font("Verdana", 0, 12);
		
		lblTitre = new JLabel("Edition d'un gestionnaire");
        lblTitre.setFont(font);
        lblTitre.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        jScrollPane1 = new JScrollPane();
		
        lblNom = new JLabel("Nom : ");
        tfNom = new JTextField();
        
        lblPrenom = new JLabel("Prenom :");
        tfPrenom = new JTextField();
        
        lblEmail = new JLabel("Email : ");
        tfEmail = new JTextField();

        lblAdresse = new JLabel("Adresse : ");
        tpAdresse = new JTextPane();
        
		lblLogin = new JLabel("Login : ");
		tfLogin = new JTextField();
		
		lblPassword = new JLabel("Password : ");
		pfPass = new JPasswordField();
        
        btnEnregistrer = new JButton("Enregistrer");
        btnEnregistrer.setFont(font);
        btnAnnuler = new JButton("Annuler");
        btnAnnuler.setFont(font);

        jScrollPane1.setViewportView(tpAdresse);
        
        placerComposants();
	}

	protected void placerComposants() {
		javax.swing.GroupLayout layout = new GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(203, 203, 203)
                .addComponent(btnEnregistrer, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnAnnuler, GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(lblNom, GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE)
                            .addComponent(lblPrenom, GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE)
                            .addComponent(lblEmail, GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE)
                            .addComponent(lblAdresse, GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE)
                            .addComponent(lblLogin, GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE)
                            .addComponent(lblPassword, GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(tfNom, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
                            .addComponent(tfPrenom, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
                            .addComponent(tfEmail, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
                            .addComponent(jScrollPane1, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
                            .addComponent(tfLogin, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
                            .addComponent(pfPass, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE))
                        .addGap(13, 13, 13))
                    .addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(lblTitre, GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
                layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(lblTitre, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(tfNom, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblNom, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                         .addComponent(tfPrenom, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblPrenom, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(tfEmail, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblEmail, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                 .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 75, GroupLayout.PREFERRED_SIZE)
                                 .addComponent(lblAdresse, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE))
                         .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                         .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                              .addComponent(tfLogin, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
                              .addComponent(lblLogin, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE))
                          .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                          .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                               .addComponent(pfPass, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
                               .addComponent(lblPassword, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE))
                                     
                     .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGap(18, 18, 18)
                    .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(btnAnnuler)
                        .addComponent(btnEnregistrer))
                    .addContainerGap())
            );
		
		
	}

	public void addEnregistrerListener(ActionListener al){
		btnEnregistrer.addActionListener(al);
	}
	
	public void addAnnulerListener(ActionListener al){
		btnAnnuler.addActionListener(al);
	}
	
	public String getValeurNom(){
		return tfNom.getText();
	}
	
	public String getValeurPrenom(){
		return tfPrenom.getText();
	}
	
	public String getValeurEmail(){
		return tfEmail.getText();
	}
	
	
	public String getValeurLogin() {
		return tfLogin.getText();
	}
	
	public String getValeurPassword() {
		return pfPass.getText().trim();
	}
	
	public String getValeurAdresse(){
		return tpAdresse.getText();
	}
	
	
	public void setValeurLogin(String s) {
		tfLogin.setText(s);
	}
	
	public void setValeurPass(String s) {
		pfPass.setText(s);
	}
	
	public void setValeurNom(String v){
		tfNom.setText(v);
	}
	public void setValeurPrenom(String v){
		tfPrenom.setText(v);
	}
	public void setValeurEmail(String v){
		tfEmail.setText(v);
	}
	
	public void setValeurAdresse(String v){
		tpAdresse.setText(v);
	}

	public void setGestionnaire(GestionnaireModel emp) {
		setValeurNom(emp.getNom());
		setValeurPrenom(emp.getPrenom());
		setValeurEmail(emp.getEmail());
		setValeurAdresse(emp.getAdresse());
		setValeurLogin(emp.getLogin());
		setValeurPass(emp.getMotDePasse());
	}
	
}

